<?php 
/**
 * 类型管理控制器
 */
class TypeController extends AuthController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model = K('Type');
	}
	
	public function index(){
		$data = $this->model->all();
		$this->assign('data',$data);
		
		$this->display();
	}
	
	/**
	 * 添加类型
	 */
	public function add(){
		
		if(IS_POST){
			if(!$this->model->addType()) $this->error($this->model->error);
			$this->success('添加成功',U('Admin/Type/add'));
		}
		
		$this->display();
	}
	
	/**
	 * 修改类型
	 */
	public function edit(){
		$tid = Q('get.tid');
		if(IS_POST){
			if(!$this->model->edit($tid)) $this->error($this->model->error);
			$this->success('修改成功',U('Admin/Type/index'));
		}
		$data = $this->model->where("tid={$tid}")->find();
		$this->assign('data',$data);
		
		$this->display();
	}
	
	/**
	 * 删除类型
	 */
	public function delete(){
		$tid = Q('get.tid');
		$this->model->where("tid={$tid}")->delete();
		$this->success('删除成功',U('index'));
	}
	
	
	
	
}














 ?>